package com.dyh.hissystem.controller;

import com.dyh.hissystem.dto.User;
import com.dyh.hissystem.service.UserService;
import com.dyh.hissystem.util.RespUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author Administrator
 */


@CrossOrigin
@RestController
@Log4j2
public class LoginController{
    private final UserService userService;
    public LoginController(UserService userService){
        this.userService = userService;
    }

    @PostMapping("/login")
    public RespUtil checkLogin(@RequestBody Map<String,String> loginUser){
        User user = userService.findOneUser(loginUser.get("username"));
        log.info(user);
        if(loginUser.get("username").equals(user.getUserName())){
            if(loginUser.get("password").equals(user.getPassword())){
                log.info(user.getUserName()+"登录了系统"+user.getPassword());
                return RespUtil.success(user);
            }else {
                log.info("密码错误");
                return RespUtil.error("密码错误");
            }
        }else{
            log.info("用户名不存在");
            return RespUtil.error("查询不到用户名");
        }
    }
}
